package cn.hh.wechatkit.pojo.card.enums;

import cn.hh.wechatkit.exception.Wx_Exception_InvalidParam;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * Created this one by HMH on 2017/7/4.
 */
@Getter
public enum Wx_CardTypeEnum {

    GROUPON("团购"),
    CASH("代金券"),
    DISCOUNT("折扣券"),
    GIFT("兑换券"),
    GENERAL_COUPON("优惠券"),
    MEETING_TICKET("会议"),
    SCENIC_TICKET("景区门票"),
    MOVIE_TICKET("电影票"),
    BOARDING_PASS("飞机票")
    ;

    String msg;

    Wx_CardTypeEnum(String msg) {
        this.msg = msg;
    }

    private static final Map<String, Wx_CardTypeEnum> stringToEnum = new HashMap<>();
            static{
                for(Wx_CardTypeEnum e : values()){
                    stringToEnum.put(e.name(), e);
                }
            }

            public static Wx_CardTypeEnum fromString(String name,String fieldName){
                Wx_CardTypeEnum result = stringToEnum.get(name);
                if (result == null) {
                    throw new Wx_Exception_InvalidParam(fieldName+"枚举字段错误");
                }
                return result;
            }
}
